<template>
  <div>
    <div style="height: 50px;text-align: left">
      <el-form  :inline="true" :model="fromInline" class="demo-form-inline">
        <el-form-item>
          <el-input v-model="formInline.name" placeholder="输入要查找的城市名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="query" type="primary" >查询</el-button>
          <el-button @click="delSome" type="primary">删除选中的数据</el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-table
        stripe
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"

        style="width: 100%;line-height: 40px"
        @selection-change="handleSelectionChange">
      <el-table-column
          type="selection"
          width="155">
      </el-table-column>
      <el-table-column
          prop="city_number"
          label="城市编号"
          width="250">
      </el-table-column>
      <el-table-column
          prop="province"
          label="所属省"
          width="250">
      </el-table-column>
      <el-table-column
          prop="name"
          label="城市名称"
          width="250"
          show-overflow-tooltip>
      </el-table-column>

      <el-table-column  label="操作" width="120">
        <template slot scope="scope">
          <el-button type="text" size="small" @click="delOneRow(scope.row)">删除</el-button>
        </template>
      </el-table-column>

    </el-table>
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNum"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>
  </div>

</template>

<script>
import {cityList} from "@/api/city";

export default {
  components: {},
  data() {
    return{
      tableData:[],
      multipleSelection: [],
      pageNum:1,
      pageSize:8,
      pageSizes:[8,16,24],
      total:0,
      formInline:{
        name:''
      },
    }
  },
  created() {
    this.getCity({
      pageNum:this.pageNum,
      pageSize:this.pageSize,
    })
  },
  mounted() {
  },
  methods:{
    query(){
      this.pageNum=1
      this.getCity({
        pageNum:this.pageNum,
        pageSize:this.pageSize,
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // delSome(){
    //   let length=this.multipleSelection.length
    //   if(length<1){
    //     this.$message({type:'error',message:'至少选择一条数据'})
    //     return
    //   }
    //   this.$confirm('删除后无法恢复，是否继续？','警告',{
    //     confirmButtonText:'确定',
    //     cancelButtonText:'取消',
    //     type:"warning"
    //   }).then(()=> {
    //     let ids = ""
    //     for(let i=0;i<length;i++){
    //       if(i<length-1){ids+=this.multipleSelection[i].id+","}
    //       else {ids+=this.multipleSelection[i].id}
    //     }
    //     delMore({
    //       ids
    //     }).then(res=>{
    //       if(res.code==200){
    //         this.$message({type:'success',message:'删除成功'})
    //         this.getUsers({
    //           pageNum:this.pageNum,
    //           pageSize:this.pageSize,
    //         })
    //       }else {
    //         this.$message({type:'error',message:res.msg})
    //       }
    //
    //     }).catch(error=>{})
    //   }).catch(()=>{
    //     this.$message({type:'info',message:'已取消删除'})
    //   })
    // },
    getCity(params){
      cityList(params).then(res=>{
            this.tableData = res.data.list;
            this.total = res.data.total
          }
      ).catch(error=>{})
    },
    handleCurrentChange(val){
      this.pageNum=val;
      this.getCity({
        pageNum:this.pageNum,
        pageSize:this.pageSize,
      })
    },
    handleSizeChange(val){
      this.pageSize=val;
      this.pageNum=1;
      this.getCity({
        pageNum:this.pageNum,
        pageSize:this.pageSize,
      })
    },
    // delOneRow(row){
    //   this.$confirm('删除后无法恢复，是否继续？','警告',{
    //     confirmButtonText:'确定',
    //     cancelButtonText:'取消',
    //     type:"warning"
    //   }).then(()=>{
    //     delOne({id:row.id}).then(res=>{
    //       if(res.code==200){
    //         this.$message({type:'success',message:'删除成功'})
    //         this.getUsers({
    //           pageNum:this.pageNum,
    //           pageSize:this.pageSize,
    //           realname: this.formInline.realname
    //         })
    //       }else {
    //         this.$message({type:'error',message:res.msg})
    //       }
    //     })
    //   }).catch(()=>{
    //     this.$message({type:'info',message:'已取消删除'})
    //   })
    // },
  }
}
</script>

<style scoped>
.demo-form-inline{

}

</style>
